import sys

import pygame
import pygame_menu


class ReplayMenu:
    """游戏结束后的菜单"""
    def __init__(self, settings, game, bullets) -> None:
        self.replay_game_menu = pygame_menu.Menu('End Game ?',
                                                 settings.sizes['screen_width'] * 0.6,
                                                 settings.sizes['screen_height'] * 0.6,
                                                 theme = pygame_menu.themes.THEME_GREEN)

        self.replay_game_menu.add.button('Play Again', self.restart_game)
        self.replay_game_menu.add.button('Quit', self.quit_game)
        self.game = game
        self.bullets = bullets


    def restart_game(self) -> None:
        """重新开始游戏"""
        self.game.run_game()
        self.bullets.empty() # 清空子弹编组
        self.alliens.empty() # 清空外星人编组
        print('Play Again')

    def quit_game(self) -> None:
        """退出游戏"""
        print('Quit Game')
        pygame.quit()
        sys.exit()